package cook

import (
	"fmt"
	"goroutine/Sushi"
	"time"
)

type Cook struct {
	id int
	//添加速度
	S        int
	workload int
	finished int
}

func (receiver Cook) Getid() int {
	return receiver.id
}
func (receiver Cook) ToString() string {
	s := fmt.Sprintf("%d号厨师已经做了%d个寿司，一共要做%d个寿司", receiver.id, receiver.finished, receiver.workload)
	return s
}
func Getcooker(id int, S int, workload int) Cook {
	c := Cook{id: id, S: S, workload: workload, finished: 0}
	return c
}
func (receiver *Cook) PutSushi(transporter sushi.Transporter, cookfinished chan bool, materialUsed chan bool) {
	for {
		s := sushi.GetSushi(receiver.id)
		transporter <- s
		fmt.Printf("%d号厨师向传送带放入%d号寿司\n", receiver.id, s.Getid())
		time.Sleep(time.Millisecond * time.Duration(receiver.S))
		receiver.finished++
		materialUsed <- true
		if receiver.workload <= receiver.finished {
			fmt.Printf("%d号厨师下班了！！！！！\n", receiver.id)
			cookfinished <- true
			break
		}
	}
}
